namespace System.Web.Core
{
    public abstract class Property
    {
        protected object originalValue;
        protected object objectValue;
        protected bool isValueInitialized = false;
        public bool isDBProperty = true;

        public virtual object ObjectValue
        {
            get
            {
                return objectValue;
            }
            set
            {
                if (!isValueInitialized)
                {
                    originalValue = value;
                    isValueInitialized = true;
                }
                objectValue = value;
            }
        }
        public virtual bool IsDirty
        {
            get
            {
                return !Equals(originalValue, objectValue);
            }
        }
        public bool IsDBProperty
        {
            get
            {
                return isDBProperty;
            }
            set
            {
                isDBProperty = value;
            }
        }
        public override string ToString()
        {
            if (objectValue != null)
            {
                return objectValue.ToString();
            }
            return null;
        }
        protected internal void SetDefaultValue(object defaultValue)
        {
            this.objectValue = defaultValue;
        }
    }
    public class Property<T> : Property
    {
        public Property()
        {
            SetDefaultValue(Globals.ChangeType<T>(objectValue));
        }
        public T Value
        {
            get
            {
                return Globals.ChangeType<T>(objectValue);
            }
            set
            {
                if (!isValueInitialized)
                {
                    originalValue = value;
                    isValueInitialized = true;
                }
                objectValue = value;
            }
        }
    }
}
